package com.neusoft.yiyang.medical.controller;

import com.neusoft.yiyang.common.entity.medical.DrugDict;
import com.neusoft.yiyang.medical.service.DrugDictService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "药品字典管理接口", description = "负责药品信息的增删改查，维护系统中的药品基础数据")
@RestController
@RequestMapping("/drug-dicts")
public class DrugDictController {

    @Autowired
    private DrugDictService drugDictService;

    @Operation(summary = "添加药品字典", description = "新增药品信息到字典库（含药品名称、规格、用法等）")
    @PostMapping("/add")
    public void addDrugDict(
            @Parameter(description = "药品信息（含通用名、规格、生产厂家等）", required = true)
            @RequestBody DrugDict drugDict) {
        drugDictService.addDrugDict(drugDict);
    }

    @Operation(summary = "获取所有药品字典", description = "查询系统中所有已录入的药品信息列表")
    @GetMapping("/all")
    public List<DrugDict> getAllDrugDicts() {
        return drugDictService.getAllDrugDicts();
    }

    @Operation(summary = "按药品通用名查询", description = "通过药品通用名模糊搜索药品信息")
    @GetMapping("/search")
    public List<DrugDict> getDrugDictByName(
            @Parameter(description = "药品通用名（支持模糊匹配）", required = true)
            @RequestParam String genericName) {
        return drugDictService.getDrugDictByName(genericName);
    }

    @Operation(summary = "更新药品字典", description = "修改已存在的药品信息（如规格、用法用量等）")
    @PutMapping("/update")
    public void updateDrugDict(
            @Parameter(description = "更新后的药品信息（含药品ID）", required = true)
            @RequestBody DrugDict drugDict) {
        drugDictService.updateDrugDict(drugDict);
    }

    @Operation(summary = "删除药品字典", description = "根据药品ID移除字典中的药品记录")
    @DeleteMapping("/delete/{drugId}")
    public void deleteDrugDict(
            @Parameter(description = "药品ID", required = true)
            @PathVariable Integer drugId) {
        drugDictService.deleteDrugDict(drugId);
    }

    @Operation(summary = "根据药品ID查询详情", description = "获取指定药品的完整信息（含规格、禁忌等）")
    @GetMapping("/getByDrugId/{drugId}")
    public DrugDict getByDrugId(
            @Parameter(description = "药品ID", required = true)
            @PathVariable Integer drugId) {
        return drugDictService.getByDrugId(drugId);
    }
}